import java.util.Scanner;
 
public class Main {
    static int N=1001;
    
    public static void main(String []args) {
        Scanner scan = new Scanner(System.in);
        int a[][] = new int[N][N];
        int b[][] = new int[N][N];
        int c[][] = new int[N][N];
        int n = scan.nextInt();
        int q = scan.nextInt();
        int res = 0;
        while(q-->0){
            int x = scan.nextInt();
            int y = scan.nextInt();
            int z = scan.nextInt();
            a[x][y]++;
            b[x][z]++;
            c[y][z]++;
            if(a[x][y]>=n) res++;
            if(b[x][z]>=n) res++;
            if(c[y][z]>=n) res++;
            //或if(++a[x][y]>=n) res++;
            //	if(++b[x][z]>=n) res++;
            //	if(++c[y][z]>=n) res++;
            System.out.println(res);
        }
 
    }
}